<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <form action="index.php?r=config" id="form-list" method="post">
                    <input type="hidden" name="actionType" value="delete" >
                    <input type="hidden" name="cfg_id" value="" >
                    <div class="table-responsive">
                        <table class="table ">
                            <thead>
                            <tr>
                                <th width="20%">配置类型</th>
                                <th width="20%">配置KEY</th>
                                <th width="40%">配置值</th>
                                <th width="20%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            foreach ($configList as $config){
                                ?>
                                <tr>
                                    <td><?php echo ConstantVar::$configType[$config['cfg_type']]; ?></td>
                                    <td><?php echo $config['cfg_type'].'-'.$config['cfg_key']; ?></td>
                                    <td width="30%">
                                        <?php echo $config['cfg_value']; ?>
                                    </td>
                                    <td>
                                        <button type="button" class="btn btn-primary btn-sm m-l-5" onclick="edit(<?php echo $config['cfg_id']; ?>)" >编辑</button>
                                        <?php
                                        if($config['ismust']!=1){
                                            ?>
                                            <button type="button" class="btn btn-danger btn-sm m-l-5" onclick="del(<?php echo $config['cfg_id']; ?>)" >删除</button>
                                            <?php
                                        }
                                        ?>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php
    if(isset($updateconfig)){
        ?>
        <div class="col-lg-12">
            <div class="card">
                <div class="card-title">
                    编辑配置
                </div>
                <div class="card-body">
                    <form method="post" id="form-edit" action="index.php?r=config">
                        <input type="hidden" name="actionType" value="updatedo" >
                        <input type="hidden" name="cfg_id" value="<?php echo $updateconfig['cfg_id']; ?>" >
                        <?php
                        if($updateconfig['ismust'] == 1){
                            ?>
                            <div class="form-group">
                                <label>配置KEY</label>
                                <input class="form-control" type="text" value="<?php echo $updateconfig['cfg_key']; ?>" disabled="">
                            </div>
                            <?php
                        }else{
                            ?>
                            <div class="form-group">
                                <label>配置KEY</label>
                                <input type="text" class="form-control" name="cfg_key" value="<?php echo $updateconfig['cfg_key']; ?>"
                                       placeholder="配置KEY">
                            </div>
                            <?php
                        }
                        ?>
                        <div class="form-group">
                            <label>配置值</label>
                            <textarea type="text" class="form-control" rows="5" name="cfg_value" style="height: 300px;"
                                      placeholder="配置值"><?php echo $updateconfig['cfg_value']; ?></textarea>
                        </div>
                        <button type="submit" class="btn btn-primary btn-block">保存</button>
                    </form>
                </div>
            </div>
        </div>
        <?php
    }else{
        ?>
        <div class="col-lg-12">
            <div class="card">
                <div class="card-title">
                    新增配置
                </div>
                <div class="card-body">
                    <form method="post" id="form-edit" action="index.php?r=config">
                        <input type="hidden" name="actionType" value="insert" >
                        <div class="form-group">
                            <label>配置KEY</label>
                            <input type="text" class="form-control" name="cfg_key" value=""
                                   placeholder="配置KEY">
                        </div>
                        <div class="form-group">
                            <label>配置值</label>
                            <textarea type="text" class="form-control" rows="5" name="cfg_value" value="" style="height: 300px;"
                                      placeholder="配置值"></textarea>
                        </div>
                        <button type="submit" class="btn btn-primary btn-block">保存</button>
                    </form>
                </div>
            </div>
        </div>
        <?php
    }
    ?>

    <!-- /# column -->
</div>
<!-- /# row -->
<script>
    function edit(cfg_id) {
        $("#form-list").find("input[name=actionType]").val("update");
        $("#form-list").find("input[name=cfg_id]").val(cfg_id);
        $("#form-list").submit();
    }
    function del(cfg_id) {
        $("#form-list").find("input[name=actionType]").val("delete");
        $("#form-list").find("input[name=cfg_id]").val(cfg_id);
        $("#form-list").submit();
    }
</script>